<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理-登陆</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/dist/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/template_001/css/admin/admin-login.css" media="all">
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <form class="layui-form" action="">
                <div class="layui-form-item logo-title">
                    <h1>{:sysConfig('site','site_name')} 后台登录</h1>
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-username"></label>
                    <input type="text" name="username" lay-verify="required|account" placeholder="用户名或者邮箱" autocomplete="off" class="layui-input" value="">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password"></label>
                    <input type="password" name="password" lay-verify="required|password" placeholder="密码" autocomplete="off" class="layui-input" value="">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-vercode"></label>
                    <input type="text" name="captcha" maxlength="4" lay-verify="required|captcha" placeholder="图形验证码" autocomplete="off" class="layui-input verification captcha" value="">
                    <div class="captcha-img">
                        <img id="captchaPic" src="/admin/out/captcha" onclick="this.src='/admin/out/captcha?v='+Math.random();$(this).parents().find('input[name=captcha]').val('')">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit="" lay-filter="login">登 入</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="/static/template_001/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/layui/dist/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        let form = layui.form, layer = layui.layer;
        if (top.location != self.location) top.location = self.location;
        form.on('submit(login)', function (data) {
            let _data = data.field;
            let _url = '/admin/ajax/login'
            fetch(_url, {
                method: 'post',
                body: JSON.stringify(_data),
                headers: {
                    'Content-Type': 'application/json'
                }
            }).then(function (response) {
                return response.json()
            }).then(function (res) {
                let code = res.code || 0
                if (code == '1') {
                    layer.msg('登录成功', {icon: 1, time: 700}, function () {
                        window.location = '/admin';
                    })
                    return
                }
                $('#captchaPic').click()
                layer.msg(res.msg, {icon: 2, shade: 0.3, shadeClose: true})
            })
            return false;
        })
    })
</script>
</body>
</html>